Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
Wordpress add a div around All images in Content section of "custom post type"

I want to put a div around all images which are in the content section of a specific custom post type. I tried to stitch together some answeres to questions i found here. But since i don't know the syntacs that well, i don't know what i'am doing wrong. Maybe someone can help me. Thanks in advance.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Hmm try this

add_filter("the_content", "my_content_modification");
function my_content_modification($content) {
  $post_type = get_post_type();
  $post_type_to_check = "MY_POST_TYPE";

  if ($post_type == $post_type_to_check) {
    $content = preg_replace('/<img(.*?)>/', '<div class="my-div"><img$1/></div>', $content);
  }

  return $content;
}

about 4 years ago · Juan Pablo Isaza Relatório

0

I just added the class for the img if somebody needs it in there as well. Thank you again Jordan Carter.

add_filter("the_content", "my_content_modification");
function my_content_modification($content) {
  $post_type = get_post_type();
  $post_type_to_check = "MY_POST_TYPE";

  if ($post_type == $post_type_to_check) {
    $content = preg_replace('/<img(.*?)>/', '<div class="MY_DIV"><img class="MY_IMG" $1/></div>', $content);
  }

  return $content;
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda